<template>
	<view>
		<image src="/static/work1.jpg" mode="" class="img_bg"></image>
		<view class="" style="position: absolute; top: 0; width: 100%;">
			<form @submit="formSubmit" @reset="" class="margin-t30">
				<view class="border-bottom bg_white margin-l10 margin-r10 margin-t30">
					<view class=" display justify-between align-center">
						<view class="text-36 padding-t30 padding-b30">巡检内容</view>
						<!-- <view class="display justify-between align-center padding-r30" style="color: #ff0000;">异常</view> -->
						<radio-group @change="radioChange">
							<view class="display justify-between align-center padding-r30">
								<block v-for="(item,index) in myRadio" :key="index">
									<view class="display justify-between align-center padding-l90">
										<radio style="transform:scale(0.7);" :value="item.name" :checked="index === current" />
										<view :style="item.name=='正常'?'color:#00C07F':'color:#FF5444'">{{item.name}}</view>
									</view>
								</block>
							</view>
						</radio-group>
					</view>
				</view>
				<view v-show="radiochange=='异常'" class="bg_white margin-l10 margin-r10">
					<!-- <view class="border-bottom display justify-between align-center" >
					<view class="text-36 padding-t30 padding-b30">计划整改时间</view>
					<view class="display align-center">
						<view>
						    <uni-calendar 
						    ref="calendar" 
						    :insert="false"
						    @confirm="confirm"
						     />
						     <view @click="open" >{{checkData?checkData:'请选择整改时间'}}</view>
						</view>
					</view>
				</view> -->
					<view class="">
						<!-- <view class="border-bottom display justify-between align-center" >
						<view class="text-36 padding-t30 padding-b30">隐患类型</view>
						<view class="display align-center">
							
							<picker @change="bindPickerChange" :value="index" custom-item="" :range="array" :range-key="'safety_name'">
										<view class="">
											{{array[index].safety_name}}
										</view>	
										
							</picker>
						</view>
					</view> -->

						<view class="border-bottom display justify-between align-center">
							<view class="text-36 padding-t30 padding-b30">隐患级别</view>
							<view class="display align-center">

								<picker @change="levelChange" :value="index1" custom-item="" :range="array1" :range-key="'name'">
									<view class="">
										{{array1[index1].name}}
									</view>

								</picker>
							</view>
						</view>

					</view>
				</view>
				<view class="">
					<view class="border-bottom bg_white margin-l10 margin-r10">
						<view class="text-36 padding-t30 padding-b30">设备问题描述</view>
						<view class="display align-center">
							<textarea placeholder="请输入描述信息..." name="content" v-model="content" placeholder-style="color:#999;font-size:28upx;" />
							</view>
			</view>
			<view class="border-bottom bg_white margin-l10 margin-r10">
				<view class="display justify-between align-center">
					<view class="text-36 padding-t30 padding-b30">检查照片</view>
					<view class="text-24 font-gray">图片大小限制500K,请勿上传无关内容。</view>
				</view>
				<view class="display align-center padding-b30" @tap="upAdd()">
					<image  :src="phone" class="addImage padding-r10"  v-if="phone!=''"></image>
					<image src="/static/add.png" class="addImage"></image>
				</view>
				</view>
			<view class="margin-t30" >
					<button form-type="submit" class="loginButton" :disabled= "disable_check">提交</button>
				</view>
			
			</view>
		</form>
		
		</view>
	</view>
</template>

<script>
	let that=this
	import uniCalendar from '@/components/uni-calendar/uni-calendar.vue'
	export default {
		components: {
		        uniCalendar
		    },
		data() {
			return {
				index: [0],
				index1:[0],
				yinhuanName:'请选择隐患名称',
				uid:'',
				danger_id:'',
				array: [],
				array1:[
					{
						name:'一般隐患',
						id:1
					},
					{
						name:'重大隐患',
						id:2
					}
				],
				checkData:'',
				checked:'',
				conContent:'',
				myRadio:[
					{name:'正常',id:1},
					{name:'异常',id:2}
				],
				radiochange:'正常',
				current:0,
				current1:1,
				current2:1,
				phone:'',
				safety_id:'',
				content:'',
				d_id:'',
				safety_level:1,
				disable_check:false
				
			}
		},
		onLoad(options){
			console.log(options)
			this.d_id=options.id
			console.log(this.d_id)
			var that=this
			this.uid=uni.getStorageSync('user').uid;
			this.token =uni.getStorageSync('user').token;
		},
		methods: {
				bindPickerChange: function(e) {
			            console.log('picker1发送选择改变，携带值为',e.target.value)
			            this.index = e.target.value
						this.safety_id=this.array[this.index].id
						this.safety_level=this.array[this.index1].safety_name
			        },
				levelChange:function(e){
					this.index1 = e.target.value
					console.log('picker2发送选择改变，携带值为',e.target.value)
					
					this.current2=parseInt(e.target.value)+1
					console.log(this.current2)
				},
		        open(){
		            this.$refs.calendar.open();
		        },
		        confirm(e) {
		            console.log(e);
					this.checkData=e.fulldate
		        }, 
				radioChange(e){
					console.log(e)
					this.radiochange=e.detail.value;
					this.current1=e.detail.value=='正常'?'1':'2'
					console.log(this.current1) 
					
				},
				upAdd(){
					let that = this
					uni.chooseImage({
						count:1,
						sizeType:['compressed'],
						sourceType:['camera','album'],
						success:res => {
							// console.log(JSON.stringify(res.tempFilePaths));
							const tempFilePaths=res.tempFilePaths;
							uni.uploadFile({
								url:'https://aqmore.sxpz.vip/AppApi/Public/uploadImg?c=uperTest',
								filePath: tempFilePaths[0],
								name: 'file',
								formData: {'user': 'test'},
								success: uploadFileRes => {
									that.phone=(uploadFileRes.data)
								}
							})
						},
					})	
				},
				formSubmit:function(e){
					this.disable_check=true
					var that=this
					this.content=e.detail.value.content
					console.log(this.content)
						// console.log('uid='+this.uid+'&token='+this.token+'&danger_id='+this.d_id+'&status='+this.current1)测试传输的数据
						if(this.content==''){
							uni.showToast({
								title:'请输入问题描述',
								icon:'none'
							})
							this.disable_check=false
							return false
						}
						if(this.phone==''){
							uni.showToast({
								title:'请上传巡检照片',
								icon:'none'
							})
							this.disable_check=false
							return false
						}
						if(this.radiochange=='异常'){
							console.log(this.radiochange)
						uni.request({
							url:'https://aqmore.sxpz.vip/AppApi/SafetyInspection/setInspection?uid='+this.uid+'&token='+this.token+'&danger_id='+this.d_id+'&img='+this.phone+'&remark='+this.content+'&status='+this.current1+'&safety_level='+this.safety_level,
							method:'GET',
							header:{'content-type':'application/x-www-form-urlencoded'},
							success:function(res){
								if(res.data.code==200){
								console.log(res)
								that.disable_check=true
								
								uni.showToast({
									title:res.data.datas.msg,
									icon:'success'
								})
								
								console.log('a')
								setTimeout(()=>{
								uni.switchTab({
									url:'../../workspace'
								})
								 },1500)
								}
								
								else if(res.data.code==400){
									uni.showToast({
										title:res.data.datas.msg,
										icon:'none'
									})
									return false
								}
							
							}
						})
						}else if(this.radiochange=='正常'){
							console.log('zhengchang')
							uni.request({
								url:'https://aqmore.sxpz.vip/AppApi/SafetyInspection/setInspection?uid='+this.uid+'&token='+this.token+'&danger_id='+this.d_id+'&img='+this.phone+'&remark='+this.content+'&status='+this.current1+'&safety_level='+this.safety_level,
								method:'GET',
								header:{'content-type':'application/x-www-form-urlencoded'},
								success:function(res){
									if(res.data.code==200){
									console.log(res)
									that.disable_check=true
									
									uni.showToast({
										title:res.data.datas.msg,
										icon:'success'
									})
									
									console.log('a')
									setTimeout(()=>{
									uni.switchTab({
										url:'../../workspace'
									})
									 },1500)
									}
									
									else if(res.data.code==400){
										uni.showToast({
											title:res.data.datas.msg,
											icon:'none'
										})
										return false
									}
								
								}
							})
						}
					
				}
		    },
	}
</script>

<style scoped>
	page{
			margin: 0;
			padding: 0;
			/* background-color: #0d98ed; */
		}
.loginButton{
		height:98upx;
		line-height: 98upx;
		background:#65caff;
		box-shadow:0 2upx 10upx 0 rgba(115, 241, 255, 0.8);
		border-radius:49upx;
		color: #fff;
		text-align: center;
		z-index: 99;
		position: relative;
	}
</style>
